

import {
    CFeature,
    CVectorLayer,
    CVector,
    CPoint,
    CIcon,
    CStyle,
    CText,
    CFill,
    CStroke,
    WebGLPointsLayer
} from '../ol'
import icon from '../../../assets/ststic/images/icon-2.png'


let features = [];
export default class Point {

    static Icons = ({ Source }) => {

        if (!Array.isArray(Source)) return {};


        Source.forEach((item) => {
            let Icons = new CFeature({
                geometry: new CPoint([item.longitude, item.latitude], "XY"),
                data: {
                    name: item.name,
                    data: item
                }
            });
            Icons.setStyle(new CStyle({
                image: new CIcon({
                    opacity: (item.opacity ? item.opacity : 1),
                    scale: (item.scale ? item.scale : 0.51),
                    src: (item.icon ? item.icon : icon),
                }),
                text: new CText({
                    font: '14px Calibri,sans-serif',
                    fill: new CFill({ color: '#fff' }),
                    stroke: new CStroke({
                        color: '#000',
                        width: 4
                    }),
                    offsetY: (item.offsetY ? item.offsetY : -35),
                    text: (item.text ? item.text : '')
                })
            }));
            features.push(Icons);

        })
        let vater = new CVector({
            features: features
        })

        let IconsLayer = new CVectorLayer({
            zIndex: 2,
            source: vater
        });

        IconsLayer.distroy = () => {
            features.forEach(item => {
                vater.removeFeature(item)
            });
            features = []
        }
        return IconsLayer;
    }


}